package com.myproject.music.service.impl;

import com.myproject.music.BizException;
import com.myproject.music.domain.Comment;
import com.myproject.music.mapper.CommentMapper;
import com.myproject.music.service.CommentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    private static final Logger log = LoggerFactory.getLogger(CommentServiceImpl.class);
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public List<Comment> selectCommentAll() {
        return commentMapper.selectCommentAll();
    }

    @Override
    public Comment selectCommentById(Long id) {
        Comment comment =commentMapper.selectCommentById(id);
        if(comment ==null){
            log.error("该评论"+id+"不存在");
            throw new BizException("该评论"+id+"不存在");
        }
        log.info("查询评论"+id+"成功");
        return commentMapper.selectCommentById(id);
    }

    @Override
    public List<Comment> selectCommentByParam(String comment) {
        return commentMapper.selectCommentByParam(comment);
    }

    @Override
    public int insertComment(Comment comment) {
        return commentMapper.insertComment(comment);
    }

    @Override
    public int updateComment(Comment comment) { return commentMapper.updateComment(comment); }

    @Override
    public int deleteCommentById(Long id) {
        return commentMapper.deleteCommentById(id);
    }

}
